package com.hns.can.safety.service;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.safety.entity.BaseBlackArchivesInfoEntity;
import com.hns.can.safety.entity.BaseLineBlackRelHisEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.DateFormater;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.UtilString;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 线路黑点分配历史
 *
 * @version Revision 2.0.0
 * @author:jeffxu
 * @email:835264047@qq.com
 */
@Service
public class BaseLineBlackRelHisService extends CommonService {

    /**
     * 查询线路黑点分配历史列表（分页）
     *
     * @param relId
     * @return
     */
    @Transactional
    public Pagination searchBaseLineBlackRelHisPage(String relId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("relId", relId);

        Pagination page = this.myBatisPage(
                "baseLineBlackRelHis.searchBaseLineBlackRelHisCnt",
                "baseLineBlackRelHis.searchBaseLineBlackRelHisList",
                paramMap, BaseLineBlackRelHisEntity.class);
        return page;
    }

    //线路黑点分配历史（启用）
    @Transactional
    public void addBaseLineBlackRelHis(SysUserEntity user, String relId) {
        BaseLineBlackRelHisEntity entity = new BaseLineBlackRelHisEntity();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        entity.setRcrdId(UtilString.getUUID());
        entity.setCorpId(user.getCorpId());
        entity.setRelId(relId);
        entity.setStrtusDate(sdf.format(new Date()));
        entity.setCrtUser(user.getId());
        entity.setCrtTime(new Date());
        entity.setUpdateUser(user.getId());
        entity.setUpdateTime(new Date());

        this.commonEntityDao.save(entity);
    }

    //线路黑点分配历史（停用）
    @Transactional
    public void uptBaseLineBlackRelHisDsablDate(SysUserEntity user, String relId) {
        String userId = user.getId();

        if (PubUtil.isNotEmpty(userId) && PubUtil.isNotEmpty(relId)) {
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", user.getId());
            paramMap.put("relId", relId);

            this.sqlMapDao.update("baseLineBlackRelHis.uptBaseLineBlackRelHisDsablDate", paramMap);
        }
    }

}